#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include "common-libs/collections/list.h"
#include "common-libs/collections/queue.h"


struct t_Planificador
{
	uint32_t IP;
	uint32_t ID;
	t_list * Buffer_Lectura;
	t_list * Buffer_Escritura;
	uint32_t TimeStamp;
 } typedef t_Planificador;


struct NodoSector{
	 uint32_t NumSector;
	 char DATA_SECTOR[513];
 } typedef NodoSector;


t_list *ColaGrabadoGeneral;
t_list *ColaLecturaGeneral;
t_queue *QueuePlanificador;


void AgregarAColaGrabado(char * SectorAgregar, uint32_t DirLogica){
	uint32_t i;
	NodoSector * NODO_AGREGAR = (NodoSector*) malloc(sizeof(NodoSector));
	NODO_AGREGAR->NumSector = DirLogica;
	for (i=0;i<513;i++){
			NODO_AGREGAR->DATA_SECTOR[i] = SectorAgregar[i];
		}
	collection_list_add( ColaGrabadoGeneral, NODO_AGREGAR);
	free(NODO_AGREGAR);

}


void AgregarColaLectura(char* SectorAgregar, uint32_t DirLogica){
	uint32_t i;
	NodoSector * NODO_AGREGAR =(NodoSector*) malloc(sizeof(NodoSector));
	NODO_AGREGAR->NumSector = DirLogica;
	for (i=0;i<513;i++){
			NODO_AGREGAR->DATA_SECTOR[i] = SectorAgregar[i];
		}
	collection_list_add( ColaLecturaGeneral, NODO_AGREGAR);
	free(NODO_AGREGAR);

}



void AlgoritmoDivisionDePedidosLectura (){            //Elegimos FIFO

	t_list * Buffer = (t_list*) malloc(sizeof(t_list));
	t_Planificador * NODO_QUEUE_AUX = (t_Planificador*) malloc(sizeof(t_Planificador));
	NODO_QUEUE_AUX = collection_queue_pop(QueuePlanificador);
	Buffer = NODO_QUEUE_AUX->Buffer_Lectura;

	NodoSector * AUX_DATA_GRABAR = (NodoSector *) malloc(sizeof(NodoSector));
	AUX_DATA_GRABAR = collection_list_get(ColaGrabadoGeneral,0);

	collection_list_add(Buffer, AUX_DATA_GRABAR);
	NODO_QUEUE_AUX->Buffer_Lectura = Buffer;


	collection_queue_push( QueuePlanificador, NODO_QUEUE_AUX );
	free(NODO_QUEUE_AUX);
	free(AUX_DATA_GRABAR);
	free(Buffer);
}

void main()
{

}
